package com.databaseconnectionmobilapi.controller;


import com.databaseconnectionmobilapi.annotation.LoginInterceptor;
import com.databaseconnectionmobilapi.domain.dto.ChangeUserInfoDTO;
import com.databaseconnectionmobilapi.domain.dto.LoginDTO;
import com.databaseconnectionmobilapi.domain.dto.RegisterDTO;
import com.databaseconnectionmobilapi.domain.entity.UserEntity;
import com.databaseconnectionmobilapi.service.UserService;
import com.databaseconnectionmobilapi.util.result.RestResult;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author fall
 * @since 2022-01-17
 */
@RestController
@AllArgsConstructor
public class UserController {
    private UserService userService;

    @LoginInterceptor
    @PostMapping("/login")
    public RestResult login(@RequestBody LoginDTO loginDto) {
        return userService.login(loginDto);
    }

    @LoginInterceptor
    @PostMapping("/register")
    public RestResult register(@RequestBody RegisterDTO registerDTO) {
        return userService.register(registerDTO);
    }

    @PostMapping("/logout")
    public RestResult logout(@RequestHeader("token") String token) {
        return userService.logout(token);
    }

    @PostMapping("/userInfo")
    public RestResult selectUserInfo(@RequestHeader("userId") Integer userId) {
        return userService.selectUserInfo(userId);
    }

    @PostMapping("/change/userInfo")
    public RestResult changeUserInfo(@RequestHeader("token") String token, @RequestBody ChangeUserInfoDTO changeUserInfoDTO) {
        return userService.changeUserInfo(token, changeUserInfoDTO);
    }

}

